﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Palsta.Core.data;

namespace Palsta.Core.exp
{
    class ExpRefNode : ExpNode
    {        
        #region Members

        private String fieldName;

        #endregion

        #region Constructors

        public ExpRefNode(String name)
        {
            this.fieldName = name;
        }

        #endregion

        #region Accessors

        public virtual String FieldName
        {
            get
            {
                String s;
                int end = this.fieldName.LastIndexOf('/');
                if (end != -1)
                {
                    s = this.fieldName.Substring(end + 1);
                }
                else
                {
                    s = this.fieldName;
                }
                return s;
            }
            set
            {
                this.fieldName = value;
            }
        }

        #endregion

        #region Methods

        public ExpNodeType GetNodeType()
        {
            return ExpNodeType.Ref;
        }


        public bool Test(DataDictionary data)
        {
            Field f = data.GetField(this.FieldName);
            if (f.GetFieldType() == FieldType.Boolean)
            {
                return ((BooleanField)f).GetBooleanValue();
            }
            else
            {
                return true;
            }
        }

        public Field GetValue(DataDictionary data)
        {
            Field f = data.GetField(this.FieldName);
            return f;
        }


        public FieldType GetFieldType(DataDictionary data)
        {
            Field f = data.GetField(this.FieldName);
            return f.GetFieldType();
        }

        public String GetValueName()
        {
            return this.FieldName;
        }

        public void SetValueName(String vn)
        {
            this.fieldName = vn;
        }

        #endregion

        #region Override Operators

        #endregion

        #region Static Methods

        #endregion

    }

}
